//
//  MainViewController.swift
//  MILHorizontalCollectionViewExample
//
//  Created by dengwei on 16/5/10.
//  Copyright © 2016年 IBM. All rights reserved.
//

import UIKit

class MainViewController: UIViewController {

    var collectionViewController : GameCollectionViewController!
    var game: [Game]?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "图片滚动"
        self.setUpCollectionViewController()
    }

    func setUpCollectionViewController(){
                
        let flow = GameCollectionViewFlowLayout()
        self.collectionViewController = GameCollectionViewController(collectionViewLayout: flow)
        
        self.addChildViewController(self.collectionViewController)
        self.collectionViewController.didMoveToParentViewController(self)
        
        self.collectionViewController.view.frame = CGRectMake(0, 30, UIScreen.mainScreen().bounds.width, 140)
         loadGameData()
        self.collectionViewController.game = game
        self.view.addSubview(self.collectionViewController.view)
        
    }
    
    private func loadGameData() {
        weak var tmpSelf = self
        GameData.loadMyGameData { (data, error) -> Void in
           // print("data=\(data)")
            if error == nil {
                if data?.data?.count > 0 {
                    tmpSelf!.game = data!.data
                } else {
                }
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
